package com.itestmini.testplatformbackend.service.impl;

import com.itestmini.testplatformbackend.dao.ITestUserMapper;
import com.itestmini.testplatformbackend.dto.ResultDto;
import com.itestmini.testplatformbackend.entity.ITestUser;
import com.itestmini.testplatformbackend.service.ITestUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

//@Component
@Service //  Service语意级别注解，底层已经实现了Comonpent注解
@Slf4j
public class ITestUserServiceImpl implements ITestUserService {

    @Autowired
    private ITestUserMapper iTestUserMapper;
    @Override
    public ResultDto<ITestUser> login(ITestUser iTestUser) {
        System.out.println("user name = " + iTestUser.getUserName());
        System.out.println("user pwd = " + iTestUser.getPassword());
        return ResultDto.success("登录成功", iTestUser);
    }

    @Override
    public ResultDto<ITestUser> save(ITestUser iTestUser) {
        iTestUser.setCreateTime(new Date());
        iTestUser.setUpdateTime(new Date());
        iTestUserMapper.insert(iTestUser);
        return ResultDto.success("insert 成功", iTestUser);
    }

    @Override
    public ResultDto<ITestUser> update(ITestUser iTestUser) {
        iTestUser.setUpdateTime(new Date());
        iTestUserMapper.updateByPrimaryKeySelective(iTestUser);
        return ResultDto.success("update 成功", iTestUser);
    }

    @Override
    public ResultDto<List<ITestUser>> getByName(ITestUser iTestUser) {
//        List<ITestUser> iTestUserList = iTestUserMapper.getByName(iTestUser.getId(),iTestUser.getUserName());
        List<ITestUser> iTestUserList = iTestUserMapper.select(iTestUser); //通过tk.mybatis工具
        return ResultDto.success("select 成功", iTestUserList);
    }

    @Override
    public ResultDto deleteUser(ITestUser iTestUser) {
        iTestUserMapper.delete(iTestUser);
        return ResultDto.success("deleteUser 成功");
    }

}
